

import requests

def main():
    api_url = "http://192.168.22.111:11434/api/embeddings"
    payload = {
        "model": "nomic-embed-text",
        "prompt": "The sky is blue because of Rayleigh scattering"
    }
    
    try:
        response = requests.post(api_url, json=payload, timeout=1000)
        response.raise_for_status()
        
        result = response.json()
        if 'embedding' in result:
            print(f"Embedding向量长度：{len(result['embedding'])}")
            print("API调用成功！")
        else:
            print("响应中未找到embedding字段")
            
    except requests.exceptions.Timeout:
        print("请求超时，请检查：\n1. Ollama服务是否启动（终端执行ollama serve）\n2. 网络连接是否正常\n3. IP地址是否正确")
    except requests.exceptions.RequestException as e:
        print(f"请求异常详情：{str(e)}")
    except ValueError:
        print("响应解析失败")

if __name__ == "__main__":
    main()


